﻿//限制只能输入数字(不可以含有小数)
function limitInt(fn) {
    jQuery(fn).keydown(function (e) {
        // 注意此处不要用keypress方法，否则不能禁用　Ctrl+V 与　Ctrl+V,具体原因请自行查找keyPress与keyDown区分，十分重要，请细查
        if (((e.keyCode > 47) && (e.keyCode < 58)) || (e.keyCode == 9) || (e.keyCode == 8) || ((e.keyCode >= 96) && (e.keyCode <= 105))) {// 判断键值  
            return true;
        } else {
            return false;
        }

    }).focus(function () {
        this.style.imeMode = 'disabled';   // 禁用输入法,禁止输入中文字符
    });

}

//tab封装
function tabs(tid, cid, tag1, tag2, addclass, theevent) {
    var checkNav = "", checkWrap = "";
    var o1 = document.getElementById(tid),
    o2 = document.getElementById(cid),
    ElementNav = new Array();
    ElementWrap = new Array();
    chk = function (e, n) {
        var v = eval("/" + n + "/gi");
        if (v == undefined) {
            return true
        }
        else if (v.test(e.className)) {
            return true
        };
    }
    function ser(e, arr, g, n) {
        var tags = e.getElementsByTagName(g), v = 0;
        for (i = 0; i < tags.length; i++) {
            if (chk(tags[i], n) == true) { arr[v] = tags[i]; v++; };
        }
    }
    function Start(e, f) {
        var s = e.length;
        for (i = 0; i < s; i++) {
            switch (theevent) {
                case "onclick":
                    {
                        e[i].onclick = function () { EV(this) }
                    }
                    break;

                default:
                    {
                        e[i].onmouseover = function () { EV(this) }
                    }
                    break;
            }
        }
        function EV(obj) {
            for (var i = 0; i < s; i++) {
                f[i].style.display = "none";
                e[i].className = "";
            }
            for (var i = 0; i < s; i++) {
                if (e[i] == obj) { f[i].style.display = "block"; e[i].className = addclass }
            }
        }
    }
    ser(o1, ElementNav, tag1, checkNav);
    ser(o2, ElementWrap, tag2, checkWrap);
    Start(ElementNav, ElementWrap)
}

//获取2位小数，不四舍五入
function Round2(temp) {
   temp=temp.toString();
    if (temp.indexOf(".") > -1) {
       return temp.substring(0, temp.indexOf(".") + 3);
    }
    else {
        return temp;
    }
}

//获取HTML标记的Left
function getLeft(obj) {
    var l = 0;
    while (obj != null) {
        l += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return l;
}

//获取HTML标记的Left
function getTop(obj) {
    var t = 0;
    while (obj != null) {
        t += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return t;
}